package it.unisalento.appsalento.activity.fragment;

import it.unisalento.R;
import it.unisalento.appsalento.activity.App;
import it.unisalento.appsalento.activity.MainActivity;
import it.unisalento.appsalento.adapter.AppelliCalendarioAdapter;
import it.unisalento.appsalento.adapter.AppelloAdapter;
import it.unisalento.appsalento.model.Appello;
import android.app.Dialog;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
//import it.unisalento.appsalento.adapter.EsamiAdapter;

/**
 * Fragment che contiene la lista degli esami sostenuti e da sostenere
 */
public class GiornoCalendarioFragment extends Fragment {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		View rootView = inflater.inflate(R.layout.fragment_giorno_calendario, container,false);
		ListView listView = (ListView) rootView.findViewById(R.id.listViewAppello);

		AppelliCalendarioAdapter adapter = new AppelliCalendarioAdapter(getActivity(), R.layout.row_appello_calendario, App.appelliForDay);
			adapter.notifyDataSetChanged();
			listView.setAdapter(adapter);
			listView.setOnItemClickListener(new OnItemClickListener() {
				public void onItemClick(AdapterView<?> parent, View v,
						int position, long id) {
					Appello appello = (Appello) parent.getItemAtPosition(position);

					Dialog dialog = new Dialog(parent.getContext());
					dialog.setContentView(R.layout.row_dettaglio_appello);
					dialog.setTitle(appello.getIdAppello() +" - " + appello.getNomeEsame());
					AppelloAdapter appelloAdapter = new AppelloAdapter();
					appelloAdapter.setAppello(appello, dialog,(MainActivity)getActivity());

					dialog.setCancelable(true);
					dialog.show();
				}

			
			});
		return rootView;
	}
	
	
	

}
